
#include "./../tools/client.h"
#include "./../../log_module/log_module_define.h"
#include <cstdint>
#include <cstdio>
#include <gtest/gtest.h>
#include <memory>
#include <string>

TEST(ConnectBaidu, Test1)
{
    std::string url = "http://www.baidu.com";
    /* Loop loop; */
    Loop loop(EPOLL);
    Client client(&loop);
    client.ConnectCallbackFunc([](std::shared_ptr<SocketBuffer> buffer){
            
        std::string line = "GET / HTTP/1.1\r\nHost: www.baidu.com\r\nAccept: */*\r\n\r\n";
        buffer->WriteData((const uint8_t*)line.c_str(), line.size());
    });
    client.MessageCallbackFunc([](std::shared_ptr<SocketBuffer> buffer){
         
        uint8_t * data = buffer->GetBufferData();
        printf("%s.\n", (char*)data);
        buffer->FreeBufferData(buffer->GetBufferLength());
    });
    client.ErrorCallbackFunc([](std::string message){

        ERROR("client error callback message : {}", message);
    });
    client.Connect(url, ClientConfig());
    loop.Run();
}

int main(int argc,char * argv[])
{
    testing::InitGoogleTest();
    LogModuleConfig config;
    config.m_log_level = "trace";
    config.m_file_name = argv[0];
    LogModule::Instance()->InitModule(config);

    return RUN_ALL_TESTS();
}
